package crs.users.dao;
// Generated 25-dic-2014 23:47:56 by Hibernate Tools 4.3.1

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import crs.users.model.UserRoles;

/**
 * Home object for domain model class UserRoles.
 * @see .UserRoles
 * @author Hibernate Tools
 */
@Repository
public class UserRolesDaoImpl implements UserRolesDao{

	private static final Log log = LogFactory.getLog(UserRolesDaoImpl.class);

	@Autowired
	private SessionFactory sf;

	public void persist(UserRoles transientInstance) {
		log.debug("persisting UserRoles instance");
		try {
			
			//Guardo el objeto usuario
			sf.getCurrentSession().persist(transientInstance);
			sf.getCurrentSession().flush();
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void remove(UserRoles persistentInstance) {
		log.debug("removing UserRoles instance");
		try {
			sf.getCurrentSession().delete(persistentInstance);
			log.debug("remove successful");
		} catch (RuntimeException re) {
			log.error("remove failed", re);
			throw re;
		}
	}

	public UserRoles merge(UserRoles detachedInstance) {
		log.debug("merging UserRoles instance");
		try {
			UserRoles result =  (UserRoles) sf.getCurrentSession().merge(detachedInstance);
			sf.getCurrentSession().flush();
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public UserRoles findById(int id) {
		log.debug("getting UserRoles instance with id: " + id);
		try {
			UserRoles instance = (UserRoles) sf.getCurrentSession().get(UserRoles.class, id);
			log.debug("get successful");
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
}
